import api from '../../api/index';
import { sdk } from '../../config/sdk';
Page({
  data: {
    loading: true
  },
  onLoad(options) {
    this.getSchool();
  },

  // 获取学校
  async getSchool() {
    const { code, message, data } = await sdk.request({ url: api.getSchool });
    if (code != 1000) return this.$error(message);
    this.setData({
      list: data,
      school: data,
      loading: false
    })
  },
  // 搜索
  search(e) {
    const school = this.data.school;
    const value = e.detail.value;
    let list = [];
    for (let i = 0; i < school.length; i++) {
      if (school[i].name.indexOf(value) != -1) {
        list.push(school[i]);
      }
    }
    this.setData({ list });
  },
  // 选择
  select(e) {
    wx.navigateBack();
    this.getOpenerEventChannel().emit('someEvent', e.currentTarget.dataset.item);
  },

  // 页面上拉触底事件的处理函数
  onReachBottom() {

  },
})